package com.sd365.permission.centre.api.controller;

import com.sd365.common.core.common.exception.BusinessException;
import com.sd365.common.core.common.exception.code.BusinessErrorCode;
import com.sd365.permission.centre.api.RoleApi;
import com.sd365.permission.centre.entity.Node;
import com.sd365.permission.centre.entity.Role;
import com.sd365.permission.centre.pojo.dto.*;
import com.sd365.permission.centre.pojo.query.RoleQuery;
import com.sd365.permission.centre.pojo.query.UserQuery;
import com.sd365.permission.centre.pojo.vo.*;
import com.sd365.permission.centre.service.RoleService;
import com.sd365.permission.centre.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/***
 * @Description roleApi的实现类
 * @class RoleController
 * @Date 2022/12/29 13:31
 * @Author hantianbing
 **/
@CrossOrigin
@RestController
public class RoleController implements RoleApi {
    /**
     * 角色服务类
     */
    private RoleService roleService;

    @Override
    public Boolean initRoleResourceRedis(Role role) {
        return null;
    }

    @Override
    public Boolean assignResource(@Valid RoleResourceDTO roleResourceDTO) {
        return roleService.assignResource(roleResourceDTO);
    }


    @Override
    public Boolean assignUser(@Valid UserRoleDTO userRoleDTO) {
        return roleService.assignUser(userRoleDTO);
    }


    @Override
    public List<Node> doQueryResourceByRoleId(@Valid RoleQuery roleQuery) {
        return roleService.queryResourceByRoleId(roleQuery.getId());
    }

    @Override
    public List<Node> selectCompany() {
        return roleService.selectCompany();
    }


    @Override
    public boolean haveRole(@Valid RoleDTO roleDTO) {
        return roleService.haveRole(roleDTO);
    }


    @Override
    public Boolean add(@Valid RoleDTO roleDTO) {
        return roleService.add(roleDTO);
    }


    @Override
    public Boolean remove(Long id, Long version) {
        return roleService.remove(id, version);
    }


    @Override
    public Boolean batchRemove(@Valid RoleDTO[] roleDTOS) {
        return roleService.batchRemove(roleDTOS);
    }


    @Override
    public RoleDTO modify(@Valid RoleDTO roleDTO) {
        return roleService.modify(roleDTO);
    }


    @Override
    public RoleDTO copy(Long id) {
        return roleService.copy(id);
    }


    @Override
    public List<RoleVO> commonQuery(RoleQuery roleQuery) {
        //非空判断
        if (null == roleQuery) {
            throw new BusinessException(BusinessErrorCode.SYSTEM_CONTROLLER_ARGUMENT_NOT_VALID, new Exception("查询对象不允许为空"));
        }
        //执行查询
        List<RoleVO> roleVos = roleService.commonQuery(roleQuery);
        return roleVos;
    }

    @Override
    public List<UserVO> commonQueryUser(UserQuery userQuery) {
        return roleService.commonQueryUser(userQuery);

    }

    @Override
    public RoleVO queryRoleById(Long id) {
        return roleService.queryById(id);
    }

    @Override
    public RoleVO queryUserResource(Long id) {
        return null;
    }

    @Override
    public RoleCompanyVO queryRoleCompanyById(Long id) {
        return roleService.queryRoleCompanyById(id);
    }

    @Override
    public Boolean modifyRoleCompany(RoleCompanyDTO roleCompanyDTO) {
        return roleService.modifyRoleCompany(roleCompanyDTO);
    }
}